﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using OpenExpressApp.Module.WPF.Editors.TreeColumn;
using System.Collections.ObjectModel;
using OpenExpressApp.Command;

namespace OpenExpressApp.WPF.Controls
{
    /// <summary>
    /// 用于给某些已有的控件添加额外的属性
    /// </summary>
    public class WPFMeta : DependencyObject
    {
        /// <summary>
        /// 这个控件对应的值，是否是必须的
        /// </summary>
        public static readonly DependencyProperty RequiredProperty =
            DependencyProperty.RegisterAttached("Required", typeof(bool), typeof(WPFMeta),
                new FrameworkPropertyMetadata(new PropertyChangedCallback(OnRequiredChanged)));
        public static readonly DependencyProperty BOPropInfoProperty =
             DependencyProperty.RegisterAttached("BOPropInfo", typeof(BusinessObjectPropertyInfo), typeof(WPFMeta));
        public static readonly DependencyProperty TreeColumnProperty =
             DependencyProperty.RegisterAttached("TreeColumn", typeof(TreeColumn), typeof(WPFMeta));
        public static readonly DependencyProperty ObjectViewProperty =
            DependencyProperty.RegisterAttached("ObjectView", typeof(ObjectView), typeof(WPFMeta));



        /// <summary>
        /// 控件对应的属性，是否是必须的
        /// </summary>
        public bool Required
        {
            get { return (bool)GetValue(RequiredProperty); }
            set { SetValue(RequiredProperty, value); }
        }
        /// <summary>
        /// 控件对应的属性
        /// </summary>
        public BusinessObjectPropertyInfo BOPropInfo
        {
            get { return (BusinessObjectPropertyInfo)GetValue(BOPropInfoProperty); }
            set { SetValue(BOPropInfoProperty, value); }
        }
        /// <summary>
        /// 用于编辑属性的列
        /// </summary>
        public TreeColumn TreeColumn
        {
            get { return (TreeColumn)GetValue(TreeColumnProperty); }
            set { SetValue(TreeColumnProperty, value); }
        }

        /// <summary>
        /// 用于保存ObjectView引用
        /// </summary>
        public ObjectView ObjectView
        {
            get { return (ObjectView)GetValue(ObjectViewProperty); }
            set { SetValue(ObjectViewProperty, value); }
        }

        private static void OnRequiredChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //在OpenExpressApp.Module.WPF.Style.dll中设置
            //(d as Label).FontWeight = FontWeights.Bold;
        }
    }
}